package com.qf.admin.controller.system;

import com.qf.admin.service.system.SysMenuService;
import com.qf.common.aspect.ApiOperationLog;
import com.qf.common.core.domain.ResponseResult;
import com.qf.common.domain.admin.dos.SysMenu;
import com.qf.common.utils.ToolUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: sin
 * @Date: 2024/10/13 15:58
 * @Description:
 **/
@Slf4j
@RestController
@RequestMapping("/admin/menu")
@Api(tags = "02.菜单接口")
public class MenuController {

    @Resource
    private SysMenuService menuService;

    @ApiOperation(value = "获取菜单")
    @ApiOperationLog(description = "获取菜单")
    @RequestMapping("/list")
    public ResponseResult<List<SysMenu>> getMenuList() {
        System.out.println("菜单");
        List<SysMenu> menus = menuService.getMenuList();
        return ResponseResult.success(menus);
    }

    @ApiOperation(value = "新增菜单")
    @ApiOperationLog(description = "新增菜单")
    @PostMapping("/save")
    public ResponseResult<Object> addMenu(@RequestBody SysMenu menu) {
        menuService.save(menu);
        return ResponseResult.success();
    }

    @ApiOperation(value = "修改菜单")
    @ApiOperationLog(description = "修改菜单")
    @PutMapping("/update")
    public ResponseResult<Object> updateById(@RequestBody SysMenu menu) {
        menuService.updateById(menu);
        return ResponseResult.success();
    }

    @ApiOperation(value = "删除菜单")
    @ApiOperationLog(description = "删除菜单")
    @DeleteMapping("/delete")
    public ResponseResult<Object> removeById(@RequestParam("ids") String ids) {
        List<Long> menuIds = ToolUtils.getLongListByString(ids);
        menuService.removeBatchByIds(menuIds);
        return ResponseResult.success();
    }
}
